package com.example.ovulationperiodtracker.Allactivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.ovulationperiodtracker.R;
import com.example.ovulationperiodtracker.databinding.ActivitySexBinding;
import com.example.ovulationperiodtracker.model.Note;
import com.example.ovulationperiodtracker.model.Settings;
import com.example.ovulationperiodtracker.utils.JCGSQLiteHelper;
import com.example.ovulationperiodtracker.utils.MyLog;
import com.example.ovulationperiodtracker.view.InputDialog;
import com.example.ovulationperiodtracker.view.NavigationView;
import com.example.ovulationperiodtracker.view.NoteUtils;
import com.necer.base.BaseActivity;
import com.shawnlin.numberpicker.NumberPicker;

import java.time.LocalDate;

public class SexActivity extends BaseActivity<ActivitySexBinding> {


    private NoteUtils.DayNote dayNote;


    @Override
    protected ActivitySexBinding createBinding(LayoutInflater inflater) {
        return ActivitySexBinding.inflate(inflater);
    }

    @Override
    protected void onCreated(Bundle savedInstanceState) {

        LocalDate localDate = (LocalDate) getIntent().getSerializableExtra("datekey");

        dayNote = NoteUtils.getDayNote(localDate);

        binding.switchTao.setChecked(dayNote.tao == 1);
        if (dayNote.sexCount != 0) {
            binding.numberPicker1.setValue(dayNote.sexCount);
        }
        if (dayNote.gaoCount != 0) {
            binding.numberPicker2.setValue(dayNote.gaoCount);
        }
        binding.tvSex.setText(dayNote.partnerName);


//        binding.switchTao.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                dayNote.tao = isChecked ? 1 : 0;
//                NoteUtils.saveDayNote(dayNote);
//            }
//        });

        binding.llSexName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new InputDialog(context, "伴侣姓名", binding.tvSex.getText().toString())
                        .setOnClickYesNoListener(new InputDialog.OnClickYesNoListener() {
                            @Override
                            public void onClickYes(String content) {
                                binding.tvSex.setText(content);
                            }
                        }).show();
            }
        });

        binding.navigation.setOnClickRightListener(new NavigationView.OnClickRightListener() {
            @Override
            public void onClickRight() {


                dayNote.partnerName = binding.tvSex.getText().toString();
                dayNote.sexCount = binding.numberPicker1.getValue();
                dayNote.gaoCount = binding.numberPicker2.getValue();
                dayNote.tao = binding.switchTao.isChecked() ? 1 : 0;
                NoteUtils.saveDayNote(dayNote);
                finish();
            }
        });
//
//        binding.numberPicker1.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
//            @Override
//            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
//                dayNote.sexCount = newVal;
//                NoteUtils.saveDayNote(dayNote);
//            }
//        });
//        binding.numberPicker2.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
//            @Override
//            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
//                dayNote.gaoCount = newVal;
//                NoteUtils.saveDayNote(dayNote);
//            }
//        });
    }
}
